"use strict";
cc._RF.push(module, '423b5ea3gtBdq2fKZGN0UKE', 'PromoSlider2');
// scripts/PromoSlider2.js

"use strict";

var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
  value: !0
});

var o = e("PromoNodeArrItem"),
    i = cc._decorator,
    a = i.ccclass,
    r = i.property,
    s = function (e) {
  __extends(t, e);

  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.mDatas = null;
    t.itemList = [];
    t.prefab = null;
    t.layout = null;
    t.scroll = !1;
    t.initPos = !1;
    t.showLeft = !1;
    return t;
  }

  t.prototype.onLoad = function () {
    SDK.Base.Event.on("getData", this.initData, this);
    this.initData();
  };

  t.prototype.onDestroy = function () {
    SDK.Base.Event.off("getData", this.initData, this);
  };

  t.prototype.initData = function () {
    if (SDK.Mgr.Inst.hasPromoData && SDK.Mgr.Inst.curChannel != SDK.Define.Channel.oppo) {
      this.node.active = !0;
      this.mDatas = Config.Base.promoData;
      this.setData();
    } else this.node.active = !1;
  };

  t.prototype.setData = function () {
    if (this.mDatas.content.length > 0) {
      for (var e = 0; e < Math.min(this.mDatas.content.length, 8); e++) {
        var t = cc.instantiate(this.prefab);
        t.parent = this.layout;
        t.active = !0;
        var n = t.getComponent(o["default"]);
        null != n && this.itemList.push(n);
        n.setData(this.mDatas.content[e]);
      }

      if (this.itemList.length > 5) {
        this.initPos = !0;
        this.scroll = !0;
      }
    }
  };

  Object.defineProperty(t.prototype, "maxLeft", {
    get: function get() {
      var e = (this.layout.height - this.layout.parent.height) / 2;
      this.scroll && (e += 20);
      return e;
    },
    enumerable: !1,
    configurable: !0
  });
  Object.defineProperty(t.prototype, "maxRight", {
    get: function get() {
      var e = (this.layout.parent.height - this.layout.height) / 2;
      this.scroll && (e -= 20);
      return e;
    },
    enumerable: !1,
    configurable: !0
  });

  t.prototype.update = function (e) {
    if (this.scroll) {
      if (this.initPos) {
        if (!(this.layout.height > 0)) return;
        this.layout.y = this.maxLeft;
        this.initPos = !1;
      }

      this.layout.y <= this.maxRight ? this.showLeft = !0 : this.layout.y >= this.maxLeft && (this.showLeft = !1);
      this.showLeft ? this.layout.y += 50 * e : this.layout.y -= 50 * e;
    } else this.layout.y = this.maxLeft;
  };

  __decorate([r(cc.Node)], t.prototype, "prefab", void 0);

  __decorate([r(cc.Node)], t.prototype, "layout", void 0);

  return __decorate([a], t);
}(cc.Component);

n["default"] = s;

cc._RF.pop();